<?php

namespace Gql;

use Gql\Commands\Tool;
use Gql\Core\Application;
use Gql\Core\Context;
use Gql\Core\DependencyTrait;
use Gql\Core\Parse;
use Illuminate\Support\ServiceProvider;

class GqlProvider extends ServiceProvider
{
    public $singletons = [
        Parse::class,
        Context::class => Context::class,
        Application::class => Application::class,
        DependencyTrait::class => DependencyTrait::class,
    ];
    protected $defer = true;

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        $this->mergeConfig();
    }

    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->publishes([
            __DIR__ . '/../config/config.php' => config_path('gql.php'),
        ]);
        $this->commands([
            Tool::class
        ]);
    }

    public function provides()
    {
        return $this->singletons;
    }

    protected function mergeConfig()
    {
        $path = realpath(__DIR__ . '/../config/config.php');
        $this->mergeConfigFrom($path, 'gql');
    }
}
